﻿//验证手机号
function checkPhone(phoneNum){
	var regPhone=/^1\d{10}$/;;
	if (!regPhone.test(phoneNum)) {
		return false;
	}else{
		return true;	
	}
}
//验证邮箱
function checkEmail(str){
	var regEmail = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	if (!regEmail.test(str)) {
		return false;
	}else{
		return true;	
	}
}

//上传
function ajaxFileUpload(url,fileId,callBack) {
	var idx = url.indexOf("?");
	if (idx != -1) {
		url += "&isAjax=true";
	}else{
		url += "?isAjax=true";
	}
	$.ajaxFileUpload(
		{
			url: url,
			secureuri: false,
			fileElementId: fileId,
			dataType: 'json',
			success: callBack,
			error: callBack
		}
	)
}



//模拟palceholder
palceHolder();
function palceHolder(obj){
$(document).ready(function(e) {
	$(document).on("click",".placeholder", function(){
		$(this).find("span").hide();
		$(this).find("input").focus();
	});
	$(document).on("focus",".placeholder input,.placeholder textarea",function(){
		$(this).parent().find("span").hide();
	});
	$(document).on("blur",".placeholder input",function(){
		if($(this).val() == ""){
			$(this).parent().find("span").show();
		}		
	});
	$(document).on("blur",".placeholder textarea",function(){
		if($(this).val() == ""){
			$(this).parent().find("span").show();
		}	
	}); 
});	
}
//判断是否支持palceholder
function isPlaceholer(){
	var input = document.createElement("input");	
	return "placeholder" in input;
}


//去掉前后空格
function trim(str) { 
	var newStr = str.replace(/(^\s*)|(\s*$)/g, "");
	return newStr; 
} 

//验证是否为汉字
function checkCn(str){
	var reg = /^[\u4E00-\u9FA5]+$/;
	if(reg.test(str)){
		return false;	
	}else{
		return true;	
	}
}

//验证座机，用空格或者-隔开(010-88888888-888)
function regTel(str){
	var reg=/^(([0,1]\d{2,3})[-, ])(\d{7,8})([-, ](\d{3,}))?$/;
	//var reg=/(^(\d{2,4}[-_－—]?)?\d{3,8}([-_－—]?\d{3,8})?([-_－—]?\d{1,7})?$)|(^0?1[35]\d{9}$)/;
	return reg.test(str);
}

//检查是否有错误没修过
function checkMsg(){
	if($("form span.red").size()>0){
		popBox("提示",$("form span.red").eq(0).text());
		return false;
	}else{
		return true;	
	}
}

//获取当前时间
function getNowTime(){
	var myDate = new Date();
	var year = myDate.getYear();
	var fullYear = myDate.getFullYear();
	var month = myDate.getMonth()+1;
	var date = myDate.getDate();
	var week = myDate.getDay();
	var timeStamp = myDate.getTime();
	var hour = myDate.getHours();
	var minutes = myDate.getMinutes();
	var second = myDate.getSeconds(); 
	return (fullYear +"-" + month +"-" + date);
}
//对Date的扩展，将 Date 转化为指定格式的String
//月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符， 
//年(y)可以用 1-4 个占位符，毫秒(S)只能用 1 个占位符(是 1-3 位的数字) 
//例子： 
//(new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423 
//(new Date()).Format("yyyy-M-d h:m:s.S")      ==> 2006-7-2 8:9:4.18 
Date.prototype.Format = function (fmt) { //author: meizz 
var o = {
   "M+": this.getMonth() + 1, //月份 
   "d+": this.getDate(), //日 
   "h+": this.getHours(), //小时 
   "m+": this.getMinutes(), //分 
   "s+": this.getSeconds(), //秒 
   "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
   "S": this.getMilliseconds() //毫秒 
};
if (/(y+)/.test(fmt))
	 fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o) {
	 if (new RegExp("(" + k + ")").test(fmt)) 
		 fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
return fmt;
}
//调用： var time1 = new Date().Format("yyyy-MM-dd");var time2 = new Date().Format("yyyy-MM-dd HH:mm:ss");
function getDateStr(millisec) {
	var d = new Date();
	d.setTime(millisec);
	
	return d.Format('yyyy-MM-dd');
}

function checkUrl(str){
	var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
	var objExp=new RegExp(Expression);
	if(objExp.test(str)==true){
		return true;
	}else{
		return false;
	}
} 